OPC Studio User's Guide and Reference
Component Services
Concepts > Development Concepts > Development Features > Component Services
In This Topic

Component services are functionality sets that are complementary to the main task of the component. They provide features that are not directly derived from the underlying communication methods of the component, but rather have to do with its integration to the environment, instrumentation (such as configuration), licensing etc.

The term service is quite overloaded. It can mean different things in different context. For example, there are OPC UA services, which are basically method calls on the OPC UA protocol level. And there are Windows services, processes that run in background on the Windows operating system. There are other uses for the term service as well. Try not to confuse the different concepts. This article is about component services, which are neither OPC UA services nor Windows services nor anything else. In this document, we strive to consistently qualify the term service with additional words, wherever needed to avoid ambiguity.

Obtaining Service Interfaces

You can obtain services from a service provider object, which is any type that derives, directly or indirectly, from the IServiceProvider interface. The major OPC Studio components, are all service providers as well.

The component services are identified by service type, which a .NET Type object, usually an interface. In order to obtain a service from a service provider, call its GetService method, passing it the type of service of you want to obtain. In most cases, the returned object is of the type you have specified (unless documented otherwise). You would therefore normally cast the received Object to the expected service type. In order to make the coding easier (in .NET), you can use the GetService<T> extension method, which saves you from using the typeof operator (in C#, or its equivalent in other languages) and from casting the result.

The GetService (or GetServiceByName) method returns a null reference when the specified interface type is not available. The set of services may depend on the various factors, such as the client object used, its configuration, software version etc. Unless you are sure that the service is available, your code should be able to handle the null result well, e.g. by gracefully degrading its functionality.

See Also